package cn.itcast.n4_共享模型_管程;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

/**
 * <p>
 * Test40_ReentrantLock_可重入性
 * </p>
 *
 * @author flyduck
 * @since 2024-10-11
 */
@Slf4j(topic = "c.Test40_ReentrantLock_可重入性")
public class Test40_ReentrantLock_可重入性 {

    private static ReentrantLock reentrantLock = new ReentrantLock();

    public static void main(String[] args) {

        reentrantLock.lock();
        try {
            log.debug("进入main方法");
            m1();
        }finally {
            reentrantLock.unlock();
        }
    }

    public static void m1(){
        reentrantLock.lock();
        try {
            log.debug("进入m1方法");
            m2();
        }finally {
            reentrantLock.unlock();
        }
    }

    public static void m2(){
        reentrantLock.lock();
        try {
            log.debug("进入m2方法");
        }finally {
            reentrantLock.unlock();
        }
    }
}
